package com.wrench.elevator.redis_test;

import com.wrench.elevator.jedis.RedisUtil;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisPubSub;

public class KeyExpiredListener extends JedisPubSub
{
    
    @Override
    public void unsubscribe()
    {
        super.unsubscribe();
    }
    
    @Override
    public void unsubscribe(String... channels)
    {
        super.unsubscribe(channels);
    }
    
    @Override
    public void subscribe(String... channels)
    {
        super.subscribe(channels);
    }
    
    @Override
    public void psubscribe(String... patterns)
    {
        super.psubscribe(patterns);
    }
    
    @Override
    public void punsubscribe()
    {
        super.punsubscribe();
    }
    
    @Override
    public void punsubscribe(String... patterns)
    {
        super.punsubscribe(patterns);
    }
    
    @Override
    public void onMessage(String channel, String message)
    {
        
    }
    
    @Override
    public void onPMessage(String pattern, String channel, String message)
    {
        JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost", 6379, 10000, "!WQ19-p0");
        
        Jedis jedis = pool.getResource();
        System.out.println(jedis.get(message + "_BACK"));
        
    }
    
    @Override
    public void onSubscribe(String channel, int subscribedChannels)
    {
        // System.out.println("channel:" + channel + "is been subscribed:" + subscribedChannels);
    }
    
    @Override
    public void onPUnsubscribe(String pattern, int subscribedChannels)
    {
        System.out.println("pattern:" + pattern + "is been subscribed:" + subscribedChannels);
    }
    
    @Override
    public void onPSubscribe(String pattern, int subscribedChannels)
    {
        System.out.println("pattern:" + pattern + "is been unsubscribed:" + subscribedChannels);
    }
    
    @Override
    public void onUnsubscribe(String channel, int subscribedChannels)
    {
        
    }
    
    public void init()
    {
        Jedis jedis = RedisUtil.getJedis();
        jedis.psubscribe(this, "__keyevent@0__:expired");
    }
    
}
